// JavaScript Document
window.history.forward();
var curIndex = 0;
jQuery(function($){
	if (self.location != top.location) { 
		top.location.href = self.location.href; 
	} 
	$("body").layout({
		north__size:		130
	,	north__closable:	false
	,	north__spacing_open:	0
	,	south__size:		8
	,	south__closable:	false
	,	south__spacing_open:	0
	,	west__size:			190
	,	west__resizable:	false
	,	east__size:			8
	,	east__closable:		false
	,	east__spacing_open:	0
	,	spacing_closed:		8
	,	togglerTip_open: "关闭"
	,	togglerTip_closed: "打开"
	,	onclose: function(pane_name){if(pane_name=='west') {$('#top_msg_menu').hide();$('#top_menu_split').hide();$('#top_menu_icon').removeClass('ui-icon-pin-s').addClass('ui-icon-pin-w');}}
	,	onopen: function(pane_name){if(pane_name=='west') {$('#top_msg_menu').show();$('#top_menu_split').show();$('#top_menu_icon').removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s');}}
	});
	
	loadLeftMenu();
	
	$("#sysbar button:first").button({
        icons: {
            primary: 'ui-icon-key'
        }
    }).next().button({
        icons: {
            primary: 'ui-icon-person'
        }
    }).next().button({
        icons: {
            primary: 'ui-icon-mail-closed'
        }
    }).next().button({
        icons: {
            primary: 'ui-icon-extlink'
        }    
    });
	
	$("#theme").dialog({
		bgiframe: false,
		autoOpen:false,
		resizable :false,
		position: 'top',
		width: 320,
		height: 110,
		modal: true
	});
	
	$("#datepicker").datepickerlunar({
		showMonthAfterYear: true,
		changeMonth: true,
		changeYear: true
	});
	
	$('#datepicker').position({
		"my": "right top",
		"at": "right bottom",
		"of": $('.date'),
		"offset": "-20 -3",
		"collision": "fit flip",
		"bgiframe": true
	});
	
	$('.date').click(function(){
		$('#datepicker').slideToggle();
	});
	
	$('#date').jclock({withDate:true, withWeek:true,dispstr:'ʱ�䣺%date(%week) %time'});
	$("#bulletin_close").click(function(){$("#bulletin").slideUp();});

	$("#bulletin_close").hover(
		function(){
			$(this).addClass("ui-state-hover");
		},
		function(){
			$(this).removeClass("ui-state-hover");
		}
	);
});

/**
 * ���������Ʋ˵�
 */
function loadLeftMenu() {
	$.ajax({
		url: 'loadUserMenu.action',   
		type:'POST',
		dataType: 'json',  
		beforeSend:function(xmlhttprequest){
		},
		success:function(data){
			var menuArray = eval(data);
			if(menuArray && menuArray.length > 0) {
				var menuString = '';
				for(var i=0; i<menuArray.length; i++) {
					menuString += '<h3><a href="#">'+menuArray[i].name+'</a></h3><div style="overflow-x:hidden;padding-bottom:1px">';
					if(menuArray[i].nodes && menuArray[i].nodes.length>0) {
						for(var j=0; j<menuArray[i].nodes.length; j++) {
							var node = menuArray[i].nodes[j];
							menuString += '<a href="'+node.url+'" target="maincontent" class="a"><div class="menu"><div class=" ui-icon ui-icon-document-b menu-background-two"></div>'+node.name+'</div></a>';
						}
					}
					menuString += '</div>';
				}
				
				showLeftMenu(menuString);
			}
			else {
				alert("����ʱû�з��ʴ���վȨ�ޣ�����ϵ����Ա��");
				window.location.href="logout.action";
			}
		},
		error:function(action, errortype, desc){
			alert("���ز˵���Ϣʧ�ܣ������������ӻ��Ժ����ԣ�");
			window.location.href="logout.action";
		}
	});
}

function showLeftMenu(menuString) {
	$('#accordion').html(menuString);
	$("#accordion").accordion({
		fillSpace: true
	});

	$('#menu').menuTree({
    });
	
	$('.menu').hover( function() {
		$(this).addClass("ui-state-hover");
	}, function() {
		$('.menu').removeClass("ui-state-hover");
	});
	
	$('.menu').click(function(){
		$('.menu').removeClass("ui-state-highlight");
		$(this).addClass("ui-state-highlight");
	});
	$('.navhome').click(function(){
		$('.menu').removeClass("ui-state-highlight");
	});
}

function openTheme(){
	$('#theme').dialog('open');
}

function changeTheme(theme){
	location.href = "saveUserTheme.action?theme="+theme;
}

